home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / utils / bbsbackup / backup.c
Encoding:
C/C++ Source or Header  |  1992-12-26  |  2.8 KB  |  128 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <exec/types.h>
  4. #include "dh0:code/code20/defines.h"
  5.  
  6. struct Commands Cmds;
  7.  
  8. char dest[200];
  9. char bbsdest[200];
  10. char bbs[200];
  11. void MakeStruct();
  12. void ReadConfig();
  13. void sr(char *str);
  14. main(int argc, char *argv[])
  15. {
  16.   if(argc!=3)
  17.   {
  18.     printf("\n");
  19.     printf("AmiExpress Structure BackUp v1.0 written by Joseph Hodge\n");
  20.     printf("\n");
  21.     printf("Usage: BACKUPBBS <complete config path> <destination Volume>\n");
  22.     printf("   ie: BACKUPBBS bbs:config1 df0:\n\n");
  23.     printf("This utility will include only 1 node to destination\n");
  24.     printf("Compatible with AmiExpress 1.1x\n\n");
  25.     exit(0);
  26.   }
  27.  
  28.   strcpy(bbs,argv[1]);
  29.   strcpy(dest,argv[2]);
  30.   sr(bbs);
  31.   sr(dest);
  32.   if(dest[strlen(dest)-1]!=':')
  33.   {
  34.     printf("Error!! Destination must be either a Device or Volume\n\n");
  35.     exit(0);
  36.   }
  37.   ReadConfig();
  38.   MakeStruct();
  39.   
  40.   printf("AmiExpress Structure Backup complete\n");
  41.   printf("\n");
  42.   exit(0);
  43. }
  44.  
  45. void ReadConfig()
  46. {
  47.   FILE *fi;
  48.   fi=fopen(bbs,"rb");
  49.   if(fi==NULL)
  50.   {
  51.     printf("Error!! can't open config file\n\n");
  52.     exit(0);
  53.   }
  54.   printf("Standby... Reading BBS configuration\n\n");
  55.   fread((APTR)&Cmds,sizeof(struct Commands),1,fi);
  56.   fclose(fi);
  57.   printf("Configuration Read\n");
  58. }
  59.  
  60. char Conf[9][60];
  61.  
  62. void MakeStruct()
  63. {
  64.   char s[200],d[200],c[200];
  65.   register int i,j,k;
  66.   strcpy(bbsdest,Cmds.BBSLoc);
  67.   if(bbsdest[strlen(bbsdest)-1]==':')
  68.      bbsdest[strlen(bbsdest)-1]='\0';
  69.   sprintf(d,"%s%s",dest,bbsdest);
  70.   mkdir(d);
  71.   sprintf(d,"%s%s/Node%d",dest,bbsdest,Cmds.AcLvl[44]);
  72.   mkdir(d);
  73.   sprintf(s,"%s/Work",d);
  74.   mkdir(s);
  75.   sprintf(s,"%s/PlayPen",d);
  76.   mkdir(s);
  77.   i=0;
  78.   while(i<9)
  79.   {
  80.     if(Cmds.ConfLoc[i][0]!='\0')
  81.     {
  82.     strcpy(Conf[i],Cmds.ConfLoc[i]);
  83.     j=0;
  84.     k=strlen(Conf[i]);
  85.     while(j<k)
  86.     {
  87.       if(Conf[i][j]==':') Conf[i][j]='/';
  88.       j++;
  89.     }
  90.      if(Conf[i][strlen(Conf[i])-1]=='/') Conf[i][strlen(Conf[i])-1]='\0';
  91.     sprintf(d,"%s%s",dest,Conf[i]);
  92.     mkdir(d);
  93.     sprintf(s,"%s/Bulletins",d);
  94.     mkdir(s);
  95.     sprintf(c,"Copy %sBulletins/#? %s",Cmds.ConfLoc[i],s);
  96.     Execute(c,NULL,NULL);
  97.     sprintf(s,"%s/MsgBase",d);
  98.     mkdir(s);
  99.     sprintf(c,"Copy %sMsgBase/#? %s",Cmds.ConfLoc[i],s);
  100.     Execute(c,NULL,NULL);
  101.     sprintf(c,"%s/LCFiles",d);
  102.     mkdir(c);
  103.     sprintf(c,"Copy %s#? %s QUIET",Cmds.ConfLoc[i],d);
  104.     Execute(c,NULL,NULL);
  105.     sprintf(s,"%s/PartUpload",d);
  106.     mkdir(s);
  107.     }
  108.     i++;
  109.   }
  110.   sprintf(s,"%sNode%d",Cmds.BBSLoc,Cmds.AcLvl[44]);
  111.   sprintf(d,"Copy %s/#? %s%s/Node%d QUIET",s,dest,bbsdest,Cmds.AcLvl[44]);
  112.   Execute(d,NULL,NULL);
  113.   sprintf(s,"Copy %s#? %s%s QUIET",Cmds.BBSLoc,dest,bbsdest);
  114.   
  115.   Execute(s,NULL,NULL);
  116. }
  117.  
  118.  
  119. void sr(char *str)
  120. {
  121.   register int i;
  122.   i=strlen(str)-1;
  123.   while(i)
  124.   {
  125.     if(*(str+i)<=' ') *(str+i)='\0'; else break;
  126.     i--;
  127.   }
  128. }